<?php

final class Flang {  
    public function __construct($mark, $size) {
        $px = $size / 8;
        $img = imagecreate($size, $size);   	
		imagecolorallocatealpha($img, 255, 255, 255, 127);
		$mark = str_split($mark);
		$this->create($img, $mark, $px);
        imagegif($img);
        imagedestroy($img);
    }
    
    protected function create($img, $mark, $px) {
        $y = $x = 0;
        foreach ($mark as $i => $new) {
			if ($i == 0) {
				$x = 0;
			} elseif (($i % 8) == 0) {
				$y += $px; $x = 0;
			} else {
				$x += $px;
			}
			$temp = $this->color($new);
			if ($temp != false) {
				$color = imagecolorallocate($img, $temp[0], $temp[1], $temp[2]);
            	imagefilledrectangle($img, $x, $y, $x + $px, $y + $px, $color);
			} else {
                $color = imagecolorallocatealpha($img, 255, 255, 255, 127);
                imagefilledrectangle($img, $x, $y, $x + $px, $y + $px, $color);
            }
        }
    }
    
	protected function color($str) {
        switch (strtolower($str)) {
            case 1: return array(0 ,0, 0);  break;
        	case 2: return array(128, 128, 128); break;
        	case 3: return array(255, 255, 255); break;
        	case 4: return array(254, 0, 0); break;
        	case 5: return array(255, 127, 0); break;
        	case 6: return array(255, 255, 0); break;
        	case 7: return array(128, 255, 0); break;
        	case 8: return array(0, 255, 1); break;
        	case 9: return array(0, 254, 129); break;
        	case 'a': return array(0, 255, 255); break;
        	case 'b': return array(0, 128, 255); break;
        	case 'c': return array(0, 0, 254); break;
        	case 'd': return array(127, 0, 255); break;
        	case 'e': return array(255, 0, 254); break;
        	case 'f': return array(255,0 ,128); break;
			default: return false; break;
		}
    }
}

if (isset($_GET['size'])) {
	$size = $_GET['size'];	
} else {
	$size = 60;
}

header('Content-Type: image/gif');
new Flang($_GET['mark'], $size);

?>